home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / dos / diverses / leda / incl / dic_m.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-15  |  4.5 KB  |  118 lines

  1. /*******************************************************************************
  2. +
  3. +  LEDA  2.1.1                                                 11-15-1991
  4. +
  5. +
  6. +  DIC_M.h
  7. +
  8. +
  9. +  Copyright (c) 1991  by  Max-Planck-Institut fuer Informatik
  10. +  Im Stadtwald, 6600 Saarbruecken, FRG     
  11. +  All rights reserved.
  12. *******************************************************************************/
  13.  
  14.  
  15. #ifndef DICTIONARY_H
  16. #define DICTIONARY_H
  17.  
  18. #include <LEDA/rb_tree.h>
  19.  
  20. typedef rb_tree_item dic_item;
  21.  
  22. #define dictionary(keytype,infotype) name3(keytype,infotype,dictionary)
  23.  
  24. #define dictionarydeclare2(keytype,infotype)\
  25. \
  26. class dictionary(keytype,infotype) : public rb_tree {\
  27. \
  28. int  cmp(ent& x, ent& y) const { return compare((keytype&)x,(keytype&)y); }\
  29. void clear_key(ent& x)   const { Clear((keytype&)x); }\
  30. void clear_inf(ent& x)   const { Clear((infotype&)x); }\
  31. void copy_key(ent& x)    const { Copy((keytype&)x); }\
  32. void copy_inf(ent& x)    const { Copy((infotype&)x); }\
  33. \
  34. public:\
  35. \
  36. virtual int      defined(keytype y) const { return rb_tree::member(Ent(y)); }\
  37. virtual dic_item lookup(keytype y)  const { return rb_tree::lookup(Ent(y)); }\
  38. virtual void     change_inf(dic_item it, infotype i)\
  39.                                      { rb_tree::change_inf(it,Ent(i)); }\
  40. \
  41. virtual dic_item insert(keytype y,infotype x)\
  42.                                      { return rb_tree::insert(Ent(y),Ent(x)); } \
  43. \
  44. virtual void     del(keytype y)          { rb_tree::del(Ent(y)); } \
  45. virtual void     del_item(dic_item it)   { rb_tree::del_item(it); } \
  46. virtual keytype  key(dic_item it)  const { return keytype(rb_tree::key(it));  }\
  47. virtual infotype inf(dic_item it)  const { return infotype(rb_tree::inf(it));}\
  48.         infotype access(keytype k) const { return inf(lookup(k));}\
  49. \
  50. virtual bool     empty() const { return rb_tree::empty(); }\
  51. virtual int      size()  const { return rb_tree::size(); }\
  52. virtual dic_item first_item() const { return rb_tree::first_item(); }\
  53. virtual dic_item next_item(dic_item it) const { return rb_tree::next_item(it); }\
  54. \
  55. virtual dictionary(keytype,infotype)& operator=(const dictionary(keytype,infotype)& D)\
  56. { return (dictionary(keytype,infotype)&)rb_tree::operator=((rb_tree&) D); }\
  57. \
  58.  dictionary(keytype,infotype)()   {}\
  59.  dictionary(keytype,infotype)(const dictionary(keytype,infotype)& D) :\
  60.   rb_tree((rb_tree&) D)   {}\
  61. ~dictionary(keytype,infotype)()   { rb_tree::clear(); }\
  62. } ;
  63.  
  64.  
  65.  
  66. #define ITEM(T) name2(T,_item)
  67.  
  68. #define DICTIONARY(ktype,itype,impl) name4(itype,ktype,impl,dictionary)
  69.  
  70.  
  71. #define DICTIONARYdeclare3(keytype,infotype,impl)\
  72. \
  73. class DICTIONARY(keytype,infotype,impl) : public dictionary(keytype,infotype),\
  74.                                           public impl {\
  75. int  cmp(ent& x, ent& y) const { return compare((keytype&)x,(keytype&)y); }\
  76. void clear_key(ent& x)   const { Clear((keytype&)x); }\
  77. void clear_inf(ent& x)   const { Clear((infotype&)x); }\
  78. void copy_key(ent& x)    const { Copy((keytype&)x); }\
  79. void copy_inf(ent& x)    const { Copy((infotype&)x); }\
  80. \
  81. public:\
  82. \
  83. int       defined(keytype y) const { return impl::member(Ent(y)); }\
  84. dic_item  lookup(keytype y)  const { return dic_item(impl::lookup(Ent(y))); }\
  85. void      change_inf(dic_item it, infotype i)\
  86.                                      { impl::change_inf(ITEM(impl)(it),Ent(i));}\
  87. \
  88. dic_item  insert(keytype y,infotype x)\
  89.                                      { return dic_item(impl::insert(Ent(y),Ent(x))); } \
  90. \
  91. void      del(keytype y)          { impl::del(Ent(y)); } \
  92. void      del_item(dic_item it)   { impl::del_item(ITEM(impl)(it)); } \
  93. keytype   key(dic_item it)  const { return keytype(impl::key(ITEM(impl)(it)));  }\
  94. infotype  inf(dic_item it)  const { return infotype(impl::inf(ITEM(impl)(it)));}\
  95. \
  96. bool  empty() const { return impl::empty(); }\
  97. int   size()  const { return impl::size(); }\
  98. dic_item first_item() const { return dic_item(impl::first_item()); }\
  99. dic_item next_item(dic_item it) const { return dic_item(impl::next_item(ITEM(impl)(it))); }\
  100. \
  101. dictionary(keytype,infotype)& operator =(const dictionary(keytype,infotype)& D)\
  102. { return (DICTIONARY(keytype,infotype,impl)&)impl::operator=((impl&) D); }\
  103. \
  104.  DICTIONARY(keytype,infotype,impl)()   {}\
  105.  DICTIONARY(keytype,infotype,impl)(const DICTIONARY(keytype,infotype,impl)& D) :\
  106.   impl((impl&) D)   {}\
  107. ~DICTIONARY(keytype,infotype,impl)()   { impl::clear(); }\
  108. } ;
  109.  
  110. // ----------------------------------------------------------------
  111. // iteration
  112. // ----------------------------------------------------------------
  113.  
  114. #define forall_dic_items(i,D) for(i = (D).first_item(); i; i=(D).next_item(i))
  115.  
  116. #endif
  117.